package org.wangblue.index;

import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.collect.Tuple;
import org.wangblue.common.Client;

import java.io.IOException;

/**
 * @Description: 删除索引
 * @Author: WangBlue
 * @Create: 2024-10-22 15:44
 * @Version: 1.0
 **/

public class DeleteIndex {
    private static final String INDEX_NAME = "user4";
    public static void main(String[] args) throws IOException {
        // 1. 创建客户端对象
        RestHighLevelClient client = Client.getClient();

        // 2. 删除索引
        DeleteIndexRequest request = new DeleteIndexRequest(INDEX_NAME);

        // 3. 发送请求, 获取响应
        AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT);

        // 4. 查询结果
        if (response.isAcknowledged()) {
            System.out.println("Deleted index " + INDEX_NAME);
        }

        // 5. 关闭链接
        client.close();
    }
}
